using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class TouchDraw : MonoBehaviour {
	
	public Camera		DrawCamera;
	public float 		DrawDepth = 10f;
	public RageSpline	DrawSpline;
	public float		UpdateRate = 0.1f;
	public int			MaxVertexCount = 100;
	
	
	Queue<Vector3> Vertices = new Queue<Vector3>();
	
	// Use this for initialization
	void Start () {
		StartCoroutine_Auto(Draw());
	}
	
	IEnumerator Draw() {
		while (true) {
			while (Input.GetMouseButton(0)) {
				Vector3 wp = DrawCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, DrawDepth));
				Vertices.Enqueue(wp);
				if (Vertices.Count > MaxVertexCount)
					Vertices.Dequeue();
				UpdateVertices();
				yield return new WaitForSeconds(UpdateRate);
			}
			yield return 0;
		}
	}
	
	void UpdateVertices() {
		
	}
	
	void OnDrawGizmos() {
		Vector3[] vertices = Vertices.ToArray();
		Gizmos.color = Color.black;
		for (int i = 1; i < vertices.Length; i++) {
			Vector3 p1 = vertices[i - 1];
			Vector3 p2 = vertices[i];
			Gizmos.DrawLine(p1, p2);
		}
	}
}
